home *** CD-ROM | disk | FTP | other *** search
/ Commodore Free 27 / Commodore_Free_Issue_27_2009_Commodore_Computer_Club.d64 / big screen vic < prev    next >
Text File  |  2023-02-26  |  9KB  |  335 lines

  1. ..
  2.  
  3.       Graphics & Bigger Screen
  4.      in BASIC on expanded VIC20
  5.  
  6. (This article has previously been
  7. posted on the VIC20 forum 'Denial':
  8.  
  9.  http://sleepingelephant.com/
  10.   denial/index.html
  11.  
  12. but this version has a few updates...)
  13. First, (as everyone probably knows),
  14. whth expansion memory (ram in block 1)
  15. then both the basic memory & screen
  16. are moved to other positions in memory
  17.  
  18. The screen now starts at: 4096 (7680
  19. on unexpanded).
  20.  
  21. The colours for the screen start at
  22. 37888 (38400 on unex.) BASIC memory
  23. starts at 18*256+1=4609 (4097 on unex)
  24.  
  25. If you are going to use expansion ram
  26. & want to use your own graphics (or a
  27. bigger screen), then you need to move
  28. BASIC memory. The reason for this is
  29. that the VIC chip only can access
  30. internal memory (not expansion memory)
  31. And by default, it only has enough
  32. memory for the default screen before
  33. BASIC memory starts. It's made this
  34. way so that all of the memory can be
  35. used for BASIC programs by default.
  36.  
  37. So you need to alter the start address
  38. of the BASIC memory & move it forward
  39. in memory to make room for things that
  40. need access to the VIC chip. So that
  41. these things can be put in internal
  42. memory.
  43.  
  44. (It is however possible to put
  45. graphics data in the internal tape
  46. buffer if you think it's enough with
  47. only 38 characters & a normal sized
  48. screen. Then you don't need to move
  49. the BASIC memory at all. More about
  50. this later.)
  51.  
  52. Moving the BASIC memory
  53. If you for example do this:
  54. POKE44,32:POKE32*256,0:NEW
  55.  
  56. Then BASIC memory will start at the
  57. expansion ram (8192) & leave the whole
  58. graphics memory free for your own
  59. graphics, a bigger screen, etc...
  60. (32*256 = 8192). You might not need to
  61. move it that far though. For example
  62. on my Tribbles game:
  63.  
  64. http://user.tninet.se/{$de}pug510w/
  65.  datormuseum/tribbles.html
  66.  
  67. I have it at 28*256 I think
  68.  (POKE 44,28:POKE28*256,0:NEW)
  69.  
  70. REMEMBER - Always load BASIC programs
  71. with just ,8 !!! If you load it ,8,1
  72. then it will be loaded to the same
  73. memory position from where it was
  74. saved, & that is not very good when
  75. you have moved BASIC memory.
  76.  
  77. A bigger screen
  78. Now when you have moved your memory,
  79. you can use some internal memory for a
  80. bigger screen. (Mostly usable on PAL
  81. where quite much of the display is
  82. unused.) You alter the screen size &
  83. positions with the following VIC
  84. registers: 
  85.  
  86. 36864 bits 0-6: screen horiz. centre
  87. 36865: screen vert. centre
  88. 36866 bits 0-6: number of columns
  89. 36867 bits 1-6: number of rows
  90.  
  91. In BASIC, to set:
  92.  
  93. screen x position: POKE 36864,x
  94. screen y position: POKE 36865,y
  95. screen width: POKE 36866,
  96.  (PEEK(36866)AND128)+w
  97. screen height: POKE 36867,
  98.  (PEEK(36867)AND129)+h*2
  99.  
  100. For an example in BASIC (& for trying
  101. different settings out), download my
  102. "overscan" program.
  103.  
  104. http://user.tninet.se/{$de}pug510w/
  105. datormuseum/oldvic20page.html#overscan
  106.  
  107. When you have opened a bigger screen
  108. with a different column size than the
  109. default, then the lines will behave
  110. strangely, but don't worry, this is
  111. normal! The system screen still is
  112. 22x23 regardless of how big your
  113. screen is, & this is why the screen
  114. seems to behave strangely. If you
  115. don't like this, then keep the
  116. original width & only make the screen
  117. taller. It's here much of the unused
  118. space is anyway (on PAL). You can't
  119. use print commands to put stuff in the
  120. extra space. So the only way (in pure
  121. BASIC) is to POKE. The screen just
  122. continues beyond where the default
  123. screen ends at 4602, so pokeing values
  124. greater than that changes the contents
  125. of the extra space on the screen. It
  126. works exactly as pokeing on the normal
  127. screen, but you just have a bigger
  128. space now. Another way is to use my
  129. "Extra Screen" program,
  130.  
  131. http://user.tninet.se/{$de}pug510w/
  132.  datormuseum/extrascreen.html
  133.  
  134. then you can use normal print commands
  135. (almost). (You are allowed to include
  136. the machine language part in your
  137. programs)
  138.  
  139. An example using "Extra screen":
  140.  
  141. 10 PRINT "{SHIFT-+}CLR{SHIFT--}This text will be put"
  142. 20 PRINT "in the extra space below"
  143. 30 PRINT "the 'normal' screen."
  144. 40 SYS 5352
  145. 50 PRINT "{SHIFT-+}CLR{SHIFT--}And this will be on
  146.  the"
  147. 60 PRINT "very top of the whole
  148.  screen."
  149.  
  150. SYS 5352 just copies the "normal"
  151. screen to below the "normal" screen in
  152. a jiffy. In other words, you don't
  153. need to start the whole "EXTRA SCREEN"
  154. program, just use this little routine
  155. to copy the screen. I did this in my
  156. Mega Omega game.
  157.  
  158. http://user.tninet.se/{$de}pug510w/
  159.  datormuseum/oldvic20page.html#omega
  160.  
  161. Graphics
  162. This is pretty straight forward. You
  163. reserve memory the way described above
  164. & then find a suitable place in memory
  165. (after the space used for the bigger
  166. screen). The register to use is:
  167. 36869 Bits 0-3
  168.  
  169. In BASIC: POKE 36869,
  170.  (PEEK(36869)AND240)+a
  171.  
  172. The addresses 'a' you can use is
  173.  
  174. 13 for 5120
  175. 14 for 6144
  176. 15 for 7168
  177. 8 for 824 (chars 103-127) &
  178.  664 (chars 83-95) (Thanks Mobsie!)
  179. 0-3 for the character ROM
  180.  
  181. So for example, POKE 36869,
  182.  (PEEK(36869)AND240)+14
  183. will use the graphics data at memory
  184. address 6144 & forward.
  185.  
  186. The easiest way to do graphics is to
  187. use some program to draw directly into
  188. the memory & then save the memory out
  189. as a file (for example with a machine
  190. language monitor). I usually use The
  191. Final Cartridge's ML monitor on the
  192. C64 to input & save the graphics. Then
  193. when you are to use it, you just load
  194. ,8,1 & it will load in the right place
  195.  
  196. The tape buffer - Selecting 8 as 'a'
  197. above makes it possible to put
  198. graphics in the internal tape buffer.
  199. For this you don't need to move the
  200. BASIC memory or anything. And it
  201. should work on both expanded & unex-
  202. panded VICs!!! Also it seems to be the
  203. only possible position if you intend
  204. to compile your program with the
  205. Austro Compiler.
  206.  
  207. ftp://ftp.zimmers.net/pub/cbm/
  208.  vic20/utilities/8k/Austro-
  209.  Compiler.prg>Austro Compiler
  210.  
  211. Here is a demo of how to use this
  212. position: Winter simulator.
  213.  
  214. http://user.tninet.se/{$de}pug510w/
  215.  datormuseum/snow.html
  216.  
  217. Working/& Saving
  218. When working on a project, it's easier
  219. to first load any graphics & ML
  220. files,8,1, then move BASIC memory as
  221. described earlier & last load the
  222. BASIC ,8. Then just save the BASIC
  223. program ,8 as you progress with better
  224. & better versions.... But when you are
  225. ready & want to turn it into something
  226. that others easily can load on their
  227. VIC... Then there are two approaches.
  228.  
  229. 1. The multiple file approach
  230. 2. Single file approach
  231.  
  232. The multiple file thing is simply that
  233. you make a loader that moves memory &
  234. loads all the files. It can be a
  235. little tricky as the NEW command is
  236. used to move the BASIC memory... A tip
  237. if you like to use this approach is to
  238. use the keyboard buffer that starts at
  239. position 631. Position 198 holds the
  240. number of letters in the buffer. So by
  241. doing this: POKE631,131:POKE198,1 You
  242. put a "LOAD/RUN" keypress in the
  243. keyboard buffer. And if you before
  244. that print something like LOAD
  245. "PROGRAM",8{SHIFT-+}up{SHIFT--}{SHIFT-+}up{SHIFT--}{SHIFT-+}up{SHIFT--} on the screen,
  246. then you can make it load a program
  247. even after the new command. Take a
  248. look at the first file of my "VIC
  249. EXTRA SCREEN" as an example.
  250.  
  251. The Single file thing is a lot nicer,
  252. & it also makes your game work on both
  253. disk & tape. It involves having 2
  254. BASIC programs as well as any graphics
  255. & ML parts in memory at the same time
  256. & then saving the whole thing. The
  257. main BASIC program at your new moved
  258. BASIC position plus a little starting
  259. program at the original BASIC position
  260. that moves memory & runs the main
  261. program.
  262.  
  263. To run a BASIC program that is some-
  264. where else in memory & not in current
  265. BASIC memory, you have to set these
  266. pointers first:
  267.  
  268. 43-44   Start of Basic
  269. 45-46   Start of Variables  First byte
  270.  after program
  271. 47-48   Start of Arrays     First byte
  272.  after program
  273. 49-50   End of Arrays       First byte
  274.  after program
  275. 51-52   String storage      End of
  276.  memory+1
  277.  
  278. Let's say we have the whole memory set
  279. up like this:
  280.  
  281. -Small Basic start
  282. -Room for bigger screen
  283. -Machine Language
  284. -Graphics Data
  285. -Main Basic program
  286.  
  287. When a program is loaded, the pointers
  288. 45,46 etc. are automatically set to
  289. behind the loaded program, & because I
  290. have the BASIC program last in the
  291. resulting file, those pointers are set
  292. by themselves when the file is loaded.
  293. Because of this, I only have to change
  294. the start pointer.
  295.  
  296. So, if you have the BASIC starting at
  297. 8192, you only have to do the
  298. following...
  299.  
  300. (RESET)
  301.  
  302. 10 POKE 44,32:RUN
  303. (make the small BASIC start)
  304.  
  305. LOAD "gfx & machine language part",8,1
  306. (loads into the graphics mem)
  307.  
  308. POKE 44,32: POKE 32*256,0: NEW
  309. (move BASIC to 8192)
  310.  
  311. LOAD "BASIC part",8
  312. (load main BASIC part)
  313.  
  314. POKE 44,18
  315. (move back the beginning of BASIC to
  316. default)
  317.  
  318. SAVE "whole program",8
  319. (And everything saves as one big file)
  320.  
  321. Very nice as you don't even have to
  322. bother to look what the ending address
  323. is...
  324.  
  325. Good luck!
  326.  
  327. Anders Persson
  328. http://listen.to/boray
  329.  
  330. Commodore Free -
  331. Would like thank Anders Persson for
  332. the reprint of the article.
  333.  
  334. ..end..
  335.